<?php
class sms_util_verifier{
	static function systemChecksum($reciever, $reciever_id, $title, $content, $sender_name, $target, $time){
		return md5($reciever."|".$reciever_id."|".$title."|".$content."|"."$sender_name"."|".$target."|".$time."|".$_SERVER['config']['sms']['syskey']);
	}
	
	static function checkLink($reciever, $reciever_id, $title, $content, $sender_name, $target, $time, $checksum){
//		Log::getInstance()->log(var_export(func_get_args(), true), LOG_DEBUG);
		return  self::systemChecksum($reciever, $reciever_id, $title, $content, $sender_name, $target, $time)== $checksum;
	}
	
	static function check($params, $checksum){
		return md5( implode("|", $params)."|".$_SERVER['config']['sms']['syskey'] ) == $checksum;
	}
	
	static function checkAllow($uid, $host_id){
		if($uid == $host_id) {
			$allow = 1;
		}else{
			$bad = Cache::cacheFunction(array("index_util_baduser", "isBad"), array($uid, $host_id), false, 120);
			if(!$bad){
				$privacy = Cache::cacheFunction(array("index_util_prop", 'getDefaultSrank'), array($uid, 'sms'), false, 120);
				if($privacy==1){
					$allow = 1;
				}elseif(!empty($privacy)){
					$allow = Cache::cacheFunction(
					array('sms_util_contactlist', 'isAllowToSend'), array($privacy, $uid, $host_id), false, 120);
				}
			}else{
				$allow = 0;
			}
		}
		return $allow;
	}
}